package cn.zxf.testwebflux.websocket;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;

import reactor.core.publisher.Mono;

@Component
public class EchoHandler implements WebSocketHandler {

    @Override
    public Mono<Void> handle( final WebSocketSession session ) {
        return session.send( session.receive()
                .map( msg -> session.textMessage( "ECHO -> " + msg.getPayloadAsText() ) ) );
    }

}
